<?php
namespace front\helpers;
/**
 * Created by PhpStorm.
 * User: ethan
 * Date: 15/10/14
 * Time: 涓嬪崍6:32
 */
class OSS extends \JohnLui\AliyunOSS\AliyunOSS
{

    public static function boot($serverName, $AccessKeyId, $AccessKeySecret)
    {
        return new self($serverName, $AccessKeyId, $AccessKeySecret);
    }

    public function getObject($bucketName, $option)
    {
        $config = array(
            'Bucket' => $bucketName
        );

        $objectListing = $this->ossClient->listObjects(array_merge($config, $option));

        $objectKeys = array();
        foreach ($objectListing->getObjectSummarys() as $objectSummary) {
            $objectKeys[] = $objectSummary->getKey();
        }
        return $objectKeys;
    }

    public function getObjectMetadata($bucketName, $option){
        $config = array(
            'Bucket' => $bucketName
        );
        $object = $this->ossClient->getObjectMetadata(array_merge($config, $option));
        $metaData = $object ->getMetadata();
        $lastMod = (array)$metaData['Last-Modified'];
        return strtotime($lastMod['date']);
    }
}